from django_filters import BaseInFilter, NumberFilter
import django_filters
from apps.equipment_maintenance_plan.models import MaintenanceSchedule, MaintenanceScheduleContent

class MaintenanceScheduleFilter(django_filters.rest_framework.FilterSet):
    date_begin = django_filters.DateFilter(field_name="date", lookup_expr='gte')
    date_end = django_filters.DateFilter(field_name="date", lookup_expr='lte')

    class Meta:
        model = MaintenanceSchedule
        fields = ['date_begin', 'date_end', 'line_id', 'daily', 'first', 'second', 'overhaul', 'inspection', 'fault',
                  'date']

class NumberInFilter(BaseInFilter, NumberFilter):
    pass

class MaintenanceScheduleContentFilter(django_filters.rest_framework.FilterSet):
    types_list = NumberInFilter(field_name='types', lookup_expr='in')
    time_range = django_filters.DateFromToRangeFilter(field_name='datetime')
    date_end = django_filters.DateFilter(field_name="datetime", lookup_expr='lte')

    class Meta:
        model = MaintenanceScheduleContent
        fields = ['id', 'schedule', 'types', 'line_id', 'performance', 'user_id', 'types_list', 'time_range',
                  'date_end']
